<html>
<head><meta charset="utf-8"><title>fallout from mir_for_ctfe PR · t-compiler/wg-polymorphization · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/index.html">t-compiler/wg-polymorphization</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/fallout.20from.20mir_for_ctfe.20PR.html">fallout from mir_for_ctfe PR</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="222711886"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/fallout%20from%20mir_for_ctfe%20PR/near/222711886" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/fallout.20from.20mir_for_ctfe.20PR.html#222711886">(Jan 14 2021 at 12:49)</a>:</h4>
<p>So... I think you said that constant items don't work anymore, and I think that is <a href="https://github.com/rust-lang/rust/blob/f6d54aa0c165da52560e5c032b4c65bb11833e0e/compiler/rustc_mir/src/monomorphize/polymorphize.rs#L83">https://github.com/rust-lang/rust/blob/f6d54aa0c165da52560e5c032b4c65bb11833e0e/compiler/rustc_mir/src/monomorphize/polymorphize.rs#L83</a></p>



<a name="222711974"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/fallout%20from%20mir_for_ctfe%20PR/near/222711974" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/fallout.20from.20mir_for_ctfe.20PR.html#222711974">(Jan 14 2021 at 12:50)</a>:</h4>
<p>we polymorphize const functions with their optimized MIR instead of the mir for CTFE, since I thought polymorphization was only used for runtime code</p>



<a name="222711991"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/fallout%20from%20mir_for_ctfe%20PR/near/222711991" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/fallout.20from.20mir_for_ctfe.20PR.html#222711991">(Jan 14 2021 at 12:50)</a>:</h4>
<p>but for associated constants which can call generic const fn, that's not true</p>



<a name="222712046"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/fallout%20from%20mir_for_ctfe%20PR/near/222712046" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/fallout.20from.20mir_for_ctfe.20PR.html#222712046">(Jan 14 2021 at 12:51)</a>:</h4>
<p>I'm not sure what to do about this...</p>



<a name="222712069"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/fallout%20from%20mir_for_ctfe%20PR/near/222712069" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/fallout.20from.20mir_for_ctfe.20PR.html#222712069">(Jan 14 2021 at 12:51)</a>:</h4>
<p>Could you describe the difference between the MIR for CTFE and the optimized MIR? I've not been following that work closely.</p>



<a name="222712353"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/fallout%20from%20mir_for_ctfe%20PR/near/222712353" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/fallout.20from.20mir_for_ctfe.20PR.html#222712353">(Jan 14 2021 at 12:53)</a>:</h4>
<p>MIR for CTFE is just some MIR that hasn't had any optimizations run that could affect UB</p>



<a name="222712375"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/fallout%20from%20mir_for_ctfe%20PR/near/222712375" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/fallout.20from.20mir_for_ctfe.20PR.html#222712375">(Jan 14 2021 at 12:53)</a>:</h4>
<p>so it's MIR from an earlier stage in the MIR opt pipeline</p>



<a name="222712447"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/fallout%20from%20mir_for_ctfe%20PR/near/222712447" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/fallout.20from.20mir_for_ctfe.20PR.html#222712447">(Jan 14 2021 at 12:54)</a>:</h4>
<p>Ah, alright</p>



<a name="222712941"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/fallout%20from%20mir_for_ctfe%20PR/near/222712941" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/fallout.20from.20mir_for_ctfe.20PR.html#222712941">(Jan 14 2021 at 12:59)</a>:</h4>
<p>So... right now what we could do is always use <code>mir_for_ctfe</code> for <code>const fn</code>, this will be slightly pessimistic for polymorphization, but I don't think it should be too bad in practice. Basically all that should change is that uses of generic parameters in dead code are considered as uses</p>



<a name="222713213"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/fallout%20from%20mir_for_ctfe%20PR/near/222713213" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/fallout.20from.20mir_for_ctfe.20PR.html#222713213">(Jan 14 2021 at 13:01)</a>:</h4>
<p>I don't quite follow why using a less optimized MIR would result in ICEs that an optimized MIR wouldn't (in fact, intuitively, I would expect the opposite, giving that an optimized MIR could have optimized away something which caused an ICE).</p>



<a name="222713820"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/fallout%20from%20mir_for_ctfe%20PR/near/222713820" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/fallout.20from.20mir_for_ctfe.20PR.html#222713820">(Jan 14 2021 at 13:07)</a>:</h4>
<p>well... the problem is that <em>right now</em> the code uses the optimized MIR for polymorphize analysis, but uses the unoptimized MIR for running const eval</p>



<a name="222714875"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/fallout%20from%20mir_for_ctfe%20PR/near/222714875" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/fallout.20from.20mir_for_ctfe.20PR.html#222714875">(Jan 14 2021 at 13:17)</a>:</h4>
<p>I made a mistake in my question, it should have been why using a less optimized MIR <em>wouldn't</em> result in ICEs. I understand that you are saying that using <code>mir_for_ctfe</code> would solve the problem (and give polymorphization more MIR to work through, as it is less optimized), but I don't understand what property of <code>mir_for_ctfe</code> means that there would no longer be a cycle error?</p>
<p>Also, the second ICE, "associated type missing default" originates from polymorphization's <code>mark_used_by_default_parameters</code>, which happens before we ask for either <code>optimized_mir</code> or <code>mir_for_ctfe</code>, that's a different issue then?</p>



<a name="222715272"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/fallout%20from%20mir_for_ctfe%20PR/near/222715272" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/fallout.20from.20mir_for_ctfe.20PR.html#222715272">(Jan 14 2021 at 13:21)</a>:</h4>
<p>I just tried using <code>mir_for_ctfe</code>, and it didn't work for either the ICE or the cycle</p>



<a name="222715316"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/fallout%20from%20mir_for_ctfe%20PR/near/222715316" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/fallout.20from.20mir_for_ctfe.20PR.html#222715316">(Jan 14 2021 at 13:21)</a>:</h4>
<p><span aria-label="sad" class="emoji emoji-2639" role="img" title="sad">:sad:</span></p>



<a name="222715329"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/fallout%20from%20mir_for_ctfe%20PR/near/222715329" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/fallout.20from.20mir_for_ctfe.20PR.html#222715329">(Jan 14 2021 at 13:21)</a>:</h4>
<p>I wonder if my PR is actually at fault for the cycle thing, it may be some other <code>const_evaluatable_unchecked</code> change</p>



<a name="222715563"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/fallout%20from%20mir_for_ctfe%20PR/near/222715563" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/fallout.20from.20mir_for_ctfe.20PR.html#222715563">(Jan 14 2021 at 13:23)</a>:</h4>
<p>I believe that the second ICE could be fixed by changing <a href="https://github.com/rust-lang/rust/blob/a4f022e1099c712fdcc8555fd10caccb1a631877/compiler/rustc_mir/src/monomorphize/polymorphize.rs#L110">this line</a> - <code>is_closure</code>, as it turns out, actually checks for both <code>DefKind::Closure</code> and <code>DefKind::Generator</code>, so the <code>type_of(..).is_generator()</code> call which results in the ICE can just be removed.</p>



<a name="222715726"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/fallout%20from%20mir_for_ctfe%20PR/near/222715726" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/fallout.20from.20mir_for_ctfe.20PR.html#222715726">(Jan 14 2021 at 13:24)</a>:</h4>
<p>I wonder if that was always true and I added that condition mistakenly or if something changed.</p>



<a name="222715847"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/fallout%20from%20mir_for_ctfe%20PR/near/222715847" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/fallout.20from.20mir_for_ctfe.20PR.html#222715847">(Jan 14 2021 at 13:25)</a>:</h4>
<p>(regardless, I might rename <code>is_closure</code> to <code>is_closure_or_generator</code>)</p>



<a name="222716044"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/fallout%20from%20mir_for_ctfe%20PR/near/222716044" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/fallout.20from.20mir_for_ctfe.20PR.html#222716044">(Jan 14 2021 at 13:27)</a>:</h4>
<p>Maybe it's because I removed <code>self.tcx.mir_keys(LOCAL_CRATE).contains(&amp;def_id)</code> during encoding without considering all the cases</p>



<a name="222716425"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/fallout%20from%20mir_for_ctfe%20PR/near/222716425" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/fallout.20from.20mir_for_ctfe.20PR.html#222716425">(Jan 14 2021 at 13:29)</a>:</h4>
<p>yea, the ICE happens on the <code>N</code> in the trait bound on the assoc const in</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">trait</span><span class="w"> </span><span class="n">Bar</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Assoc</span>: <span class="nc">Foo</span><span class="o">&lt;</span><span class="n">N</span><span class="o">&gt;</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="222717070"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/fallout%20from%20mir_for_ctfe%20PR/near/222717070" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/fallout.20from.20mir_for_ctfe.20PR.html#222717070">(Jan 14 2021 at 13:34)</a>:</h4>
<p>jup that's it</p>



<a name="222717089"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/fallout%20from%20mir_for_ctfe%20PR/near/222717089" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/fallout.20from.20mir_for_ctfe.20PR.html#222717089">(Jan 14 2021 at 13:34)</a>:</h4>
<p>we used to skip encoding mir for anon consts that have no mir body</p>



<a name="222717114"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/fallout%20from%20mir_for_ctfe%20PR/near/222717114" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/fallout.20from.20mir_for_ctfe.20PR.html#222717114">(Jan 14 2021 at 13:34)</a>:</h4>
<p><span aria-label="face palm" class="emoji emoji-1f926" role="img" title="face palm">:face_palm:</span></p>



<a name="222717136"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/fallout%20from%20mir_for_ctfe%20PR/near/222717136" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/fallout.20from.20mir_for_ctfe.20PR.html#222717136">(Jan 14 2021 at 13:35)</a>:</h4>
<p>that makes sense</p>



<a name="222717188"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/fallout%20from%20mir_for_ctfe%20PR/near/222717188" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/fallout.20from.20mir_for_ctfe.20PR.html#222717188">(Jan 14 2021 at 13:35)</a>:</h4>
<p>I have so high hopes for that PR that stops using HIR to do metadata encoding</p>



<a name="223390526"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216091-t-compiler/wg-polymorphization/topic/fallout%20from%20mir_for_ctfe%20PR/near/223390526" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/216091-t-compiler/wg-polymorphization/topic/fallout.20from.20mir_for_ctfe.20PR.html#223390526">(Jan 20 2021 at 15:42)</a>:</h4>
<p>I have a busy week, not sure I'll get to this this week, but I haven't forgotten about it</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>